package org.codefinger.dao.impl.sql.ast;

import org.codefinger.dao.impl.SQLVisitor;
import org.codefinger.dao.impl.sql.Expression;

public class CompareExpression implements Expression {

	private Expression	right;

	private Expression	left;

	private String		operator;

	public CompareExpression(Expression right, Expression left, String operator) {
		super();
		this.left = left;
		this.right = right;
		this.operator = operator;
	}

	@Override
	public boolean matchVisit(SQLVisitor visitor) {
		if (left.matchVisit(visitor)) {
			int sqlSize = visitor.getSqlSize();
			visitor.appendSQL(operator);
			if (right.matchVisit(visitor)) {
				return true;
			}
			visitor.back(sqlSize);
			return true;
		}
		if (right.matchVisit(visitor)) {
			return true;
		}
		return false;
	}

	@Override
	public void visit(SQLVisitor visitor) {
		left.visit(visitor);
		visitor.appendSQL(operator);
		right.visit(visitor);
	}
	
}
